<template>
  <div class="location">
    <!-- <div class="location-chosen">
      <div class="detail" id="Dand" @tap="choseDetail('Dang')">当</div>
      <div class="detail" id="Re"  @tap="choseDetail('Re')">热</div>
      <div
        v-for="item in searchLetter"
        class="detail"
        :key="item"
        @tap="choseDetail(item)">{{item}}</div>
    </div> -->
    <!-- <scroll-view
      class="location-scrollView"
      scroll-y> -->
      <!-- <div class="detail" id="Dang">
        <div class="title">当前城市</div>
        <div class="citys">
          <div class="city-name">
            <div class="citying-icon">
              <div class="iconfont icon-dingwei"></div>
            </div>
            {{location.city}}
          </div>
        </div>
      </div>
      <div class="detail" id="Re">
        <div class="title">热门城市</div>
        <div class="citys">
          <div class="hot-city clear">
            <div
              v-for="(item, index) in hotCityList"
              class="hot-city-row"
              :key="index">
              <div
                v-for="(child, chlidIndex) in item"
                class="hot-city-detail pull-left"
                :key="child.cityCode"
                @tap="changeLocation(child)">
                {{child.city}}
              </div>
            </div>
          </div>
        </div>
      </div> -->
      <i-index
        height="100%"
        i-class="location-list">
        <i-index-item
          v-for="(item, index) in cityList"
          i-class="location-detail"
          :name="item.initial"
          :key="item.initial">
          <view
            v-for="(child, childIndex) in item.data"
            class="city-name"
            :key="child.id"
            @tap="changeLocation(child)">
            {{child.city}}
          </view>
        </i-index-item>
      </i-index>
        <!-- <div
          v-for="(item, index) in cityList"
          class="detail"
          :key="item.initial"
          :id="item.initial">
          <div class="title">{{item.initial}}</div>
          <div class="citys">
            <div
              v-for="(child, childIndex) in item.data"
              class="city-name"
              :key="child.id"
              @tap="changeLocation(child)">
              {{child.city}}
            </div>
          </div>
        </div> -->
    <!-- </scroll-view> -->
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import { hotCityList, cityList, searchLetter } from 'common/js/city'
import { shareMixin } from 'common/js/mixins'

export default {
  mixins: [shareMixin()],
  computed: {
    ...mapState([
      'location'
    ])
  },
  created () {
    this.cityList = cityList(this.location)
  },
  mounted () {
    this.changeCurrentCity()
  },
  data () {
    return {
      hotCityList: hotCityList(),
      cityList: [],
      searchLetter: searchLetter()
    }
  },
  methods: {
    // choseDetail (key) {
    //   this.scrollId = key
    // },
    changeCurrentCity () {
      this.cityList[0].data = [
        this.location
      ]
    },
    changeLocation (child) {
      this.SET_LOCATION(child)
      wx.navigateBack()
    },
    ...mapMutations([
      'SET_LOCATION'
    ])
  }
}
</script>

<style lang="scss">
  @import '~common/scss/color';
  .location {
    width: 100%;
    height: 100%;
    background-color: rgb(248, 248, 248);
    position: relative;
    .location-list {
      .location-detail {
        .city-name {
          padding: 10px;
          background-color: white;
          border-bottom: 1px solid rgb(229, 229, 229);
        }
      }
    }
    // .location-chosen {
    //   width: 40px;
    //   position: fixed;
    //   top: 20px;
    //   right: 0;
    //   z-index: 2;
    //   > .detail {
    //     width: 100%;
    //     font-size: 12px;
    //     line-height: 22px;
    //     text-align: center;
    //     color: $color-default;
    //     &:nth-last-of-type(1) {
    //       margin-bottom: 0;
    //     }
    //   }
    // }
    // .location-scrollView {
    //   width: 100%;
    //   height: 100%;
    //   .location-list {
    //     width: 100%;
    //     height: 100%;
    //     > .detail {
    //       width: 100%;
    //       // border-top: 1px solid rgb(229, 229, 229);
    //       border-bottom: 1px solid rgb(229, 229, 229);
    //       &:nth-last-of-type(1) {
    //         border-bottom: none;
    //       }
    //       > .title {
    //         width: 100%;
    //         height: 50px;
    //         line-height: 50px;
    //         font-size: 14px;
    //         color: rgb(136, 136, 136);
    //         padding-left: 10px;
    //       }
    //       > .citys {
    //         width: 100%;
    //         background-color: white;
    //         border-top: 1px solid rgb(229, 229, 229);
    //         > .city-name {
    //           margin: 0 10px;
    //           height: 50px;
    //           border-bottom: 1px solid rgb(229, 229, 229);
    //           font-size: 16px;
    //           display: flex;
    //           align-items: center;
    //           > .citying-icon {
    //             width: 35px;
    //             color: rgb(191, 191, 191);
    //             > .iconfont {
    //               font-size: 18px;
    //             }
    //           }
    //           &:nth-last-of-type(1) {
    //             border-bottom: none;
    //           }
    //         }
    //         > .hot-city {
    //           width: 100%;
    //           padding: 15px 0;
    //           padding-right: 35px;
    //           padding-left: 10px;
    //           box-sizing: border-box;
    //           > .hot-city-row {
    //             width: 100%;
    //             display: flex;
    //             align-items: center;
    //             margin-bottom: 10px;
    //             &:nth-last-of-type(1) {
    //               margin-bottom: 0;
    //             }
    //             > .hot-city-detail {
    //               width: 100%;
    //               line-height: 40px;
    //               text-align: center;
    //               border: 1px solid rgb(217, 217, 217);
    //               border-radius: 5px;
    //               margin-right: 10px;
    //               font-size: 14px;
    //               color: rgb(178, 178, 178);
    //             }
    //           }
    //         }
    //       }
    //     }
    //   }
    // }
  }
</style>
